/**
 *******************************************************************************
 * @FileName  : smp_defs.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-02-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef SMP_DEFS_H_
#define SMP_DEFS_H_

#define SMP_HDR_LEN                   1     /*!< Attribute PDU header length. */

#define SMP_TIMEOUT_TIME              30    /*!< Protocol timeout in seconds.*/

/*! SMP Encryption Key Size. */
#define SMP_KEY_SIZE_MAX              16    /*!< Maximum encryption key size. */
#define SMP_KEY_SIZE_MIN              7     /*!< Minimum encryption key size. */

#define SMP_OOB_LEN                   16    /*!< OOB Data length in bytes.    */
#define SMP_PIN_LEN                   3     /*!< Passkey Pin length in bytes. */

/**
 * SMP opcode define.
 * @{
 */
#define SMP_RESERVED                0x00 /*<! Reserved.                    */
#define SMP_PAIR_REQ                0x01 /*<! Pairing request.             */
#define SMP_PAIR_RSP                0x02 /*<! Pairing response.            */
#define SMP_PAIR_CONFIRM            0x03 /*<! Pairing confirm.             */
#define SMP_PAIR_RANDOM             0x04 /*<! Pairing random.              */
#define SMP_PAIR_FAILED             0x05 /*<! pairing failed               */
#define SMP_ENC_INFO                0x06 /*<! encryption information       */
#define SMP_MASTER_IDENTIFICATION   0x07 /*<! master identification        */
#define SMP_ID_INFO                 0x08 /*<! identity information         */
#define SMP_ID_ADDR_INFO            0x09 /*<! identity address information */
#define SMP_SIGN_INFO               0x0A /*<! signing information          */
#define SMP_SECURITY_REQ            0x0B /*<! security request             */
#define SMP_PAIR_PUBLIC_KEY         0x0C /*<! pairing public key           */
#define SMP_PAIR_DHKEY_CHECK        0x0D /*<! pairing DHKey check          */
#define SMP_PAIR_KEYPRESS_NOTIFY    0x0E /*<! pairing keypress notify      */
#define SMP_CMD_MAX                 0x0F /*<! Command code maximum.        */
/** @} */


/**
 * @Name: SMP Value Length Constants
 *         Lengths of various keys and values.
 * @{
 */
#define SMP_RAND_LEN                  16 /*!< Random number length. */
#define SMP_CONFIRM_LEN               16 /*!< Confirm number length. */
#define SMP_KEY_LEN                   16 /*!< Key length. */
#define SMP_RAND8_LEN                 8  /*!< Random 8-byte number length. */
#define SMP_PRIVATE_KEY_LEN           32 /*!< Secure connections private key length. */
#define SMP_PUB_KEY_LEN               32 /*!< Secure connecdtions public key length. */
#define SMP_DHKEY_LEN                 32 /*!< Secure connection Diffie-Hellman key length. */
#define SMP_DHKEY_CHECK_LEN           16 /*!< Secure connection Diffie-Hellman key check length. */
/**@}*/


/**
 * @Name: SMP PDU Packet Lengths
 *        Fixed length of the PDU to be sent.
 * @{
 */
#define SMP_OPCODE_LEN                1

#define SMP_PAIR_REQ_LEN              7                          /*!< Pairing request message length.              */
#define SMP_PAIR_RSP_LEN              7                          /*!< Pairing response message length.             */
#define SMP_PAIR_CNF_LEN              17                         /*!< Pairing confirmation message length.         */
#define SMP_PAIR_RAND_LEN             17                         /*!< Pairing random message length.               */
#define SMP_PAIR_FAIL_LEN             2                          /*!< Pairing fail message length.                 */
#define SMP_ENC_INFO_LEN              17                         /*!< Encryption information message length.       */
#define SMP_MASTER_ID_LEN             11                         /*!< Master identification messagelength.         */
#define SMP_ID_INFO_LEN               17                         /*!< Identity information message length.         */
#define SMP_ID_ADDR_INFO_LEN          8                          /*!< Identity address information message length. */
#define SMP_SIGN_INFO_LEN             17                         /*!< Signing information message length.          */
#define SMP_SECURITY_REQ_LEN          2                          /*!< Security request message length.             */
#define SMP_PUB_KEY_MSG_LEN           (1 + 2*SMP_PUB_KEY_LEN)    /*!< Public key message length.                   */
#define SMP_DHKEY_CHECK_MSG_LEN       (1 + SMP_DHKEY_CHECK_LEN)  /*!< Diffie-Hellman key check message length.     */
#define SMP_KEYPRESS_MSG_LEN          2                          /*!< Keypress message length.                     */
/**@}*/


/**
 * IO Capability define.
 * @{
 */
#define IO_CAP_DISPLAY_ONLY       0x00
#define IO_CAP_DISPLAY_YES_NO     0x01
#define IO_CAP_KEYBOARD_ONLY      0x02
#define IO_CAP_NO_IO              0x03
#define IO_CAP_KEYBOARD_DISPLAY   0x04
/** @}*/


/**
 *  @Name: SMP OOB Data Flag
 *  @{
 */
#define SMP_OOB_DATA_NONE        0x00
#define SMP_OOB_DATA_PRESENT     0x01
/** @}*/

/**
 * @Name SMP Authentication Requirements Flags
 * @{
 */
#define SMP_AUTH_BOND_MASK            0x03      /*!< Mask for bonding bits. */
#define SMP_AUTH_BOND_FLAG            0x01      /*!< Bonding requested. */
#define SMP_AUTH_MITM_FLAG            0x04      /*!< MITM (authenticated pairing) requested. */
#define SMP_AUTH_SC_FLAG              0x08      /*!< LE Secure Connections requested. */
#define SMP_AUTH_KP_FLAG              0x10      /*!< Keypress notifications requested. */
/**@}*/


/**
 * @Name: SMP Key Distribution Flags
 * @{
 */
#define SMP_KEY_DIST_ENC              0x01 /*!< Distribute LTK.  */
#define SMP_KEY_DIST_ID               0x02 /*!< Distribute IRK.  */
#define SMP_KEY_DIST_SIGN             0x04 /*!< Distribute CSRK. */
/*<! Key distribution mask. */
#define SMP_KEY_DIST_MASK             (SMP_KEY_DIST_ENC | SMP_KEY_DIST_ID | SMP_KEY_DIST_SIGN)
/**@}*/

#endif /* BLH_SMP_DEFS_H_ */
